package IC.lir;

import java.util.HashMap;

public class LiteralStack 
{
	private HashMap<String, String> _literals = new HashMap<String, String>();
	private int counter = 0;
	
	public String GetLabel(String literalValue)
	{
		String label = _literals.get(literalValue);
		if (label == null)
		{
			label = CreateLabel(counter++);
			_literals.put(literalValue, label);
		}
		
		return label;
	}
	
	private String CreateLabel(int counter)
	{
		return "literal__" + counter;
	}
	
	public void clear() { _literals.clear(); }
	
	public String toString()
	{
		String ret = "";
		for (java.util.Map.Entry<String, String> entry : _literals.entrySet())
			ret += String.format("%s: \"%s\"\n", entry.getValue(), entry.getKey());
		
		return ret;
	}
}
